{include file="public/header" /}


    
<div class="x-body">
 


  <xblock>
    
    <button class="layui-btn layui-btn-sm" onclick="model_add_edit(1)"><i class="layui-icon"></i>添加</button>
    <!-- <button class="layui-btn layui-btn-sm" onclick="get_list()"><i class="layui-icon"></i>获取数据</button> -->
    
  </xblock>
  <table class="layui-table">
    <thead>
      <tr>
        <th width="50">
          <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
        </th>
        <th width="50">ID</th>
        <th>角色名称</th>
        <th>描述</th>

        <th width="100">状态</th>
        <th width="100">操作</th>
    </thead>
    <tbody>
      {foreach name="lists" item="v" key="k" }
        <tr>
          <td>
            <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon">&#xe605;</i></div>
          </td>
          <td>{$v.id}</td>
          <td>{$v.groupname}</td>
          <td>{$v.des}</td>
         
          
          <td class="td-status">
            {if condition=" $v.status == '1' "}
            <span class="layui-badge-dot layui-bg-green"></span>
            <span class="layui-badge-rim">启用</span>
            {else if condition=" $v.status == '2' " /}
            <span class="layui-badge-dot"></span>
            <span class="layui-badge-rim">冻结</span>
      

            {/if}
          </td>
          <td class="td-manage">
            
            <a title="编辑"  onclick="model_add_edit(2,'{$v.id}','{$v.groupname}','{$v.des}','{$v.status}','{$v.power}')" class="layui-btn layui-btn-normal layui-btn-xs">编辑</a>
            <a title="删除" onclick="del({$v.id})" class="layui-btn layui-btn-danger layui-btn-xs">删除</a>

          </td>
        </tr>
      {/foreach}
    </tbody>
  </table>
  <div class="page">
    <div>
    {$page}
    </div>
  </div>

</div>



<!-- --------------------js--------------------- -->

<script>

//日期选择
layui.use('laydate', function(){
  var laydate = layui.laydate;
  
  //执行一个laydate实例
  laydate.render({
    elem: '#start' //指定元素
  });

  //执行一个laydate实例
  laydate.render({
    elem: '#end' //指定元素
  });
});


  //模态窗
  function model_add_edit (type,id,groupname,des,status,power) {
    // alert(id);
    if(type == 1){
      var txt = '添加'; 
    }else{
      var txt = '编辑'; 

    }
    layui.use(['layer','form'], function() {
      var form = layui.form;    //渲染
      var layer = layui.layer; //唤起模态窗

      layer.open({
        type: 1,
        title: txt,
        area: ['800px'] ,
        shadeClose: true,
        content: $('#box2').html()
      })
      
      $('.editId').val(id);   
      $('#groupname').val(groupname);
      $('#des').val(des);
   
      $(":radio[name='status'][value="+status+"]").attr("checked","checked");  

      if(type == 2){
        var checkBoxArray = power.split(",");
        for(var i=0;i<checkBoxArray.length;i++){  
          $("#qx"+checkBoxArray[i]).attr("checked","checked"); 
          // $("input[name='power']").attr("checked","checked"); 
        }
      }

      form.render();//渲染

    })
  }


//确定-提交
function sub(){

  var power = get_checkobx('power');
  var groupname = $('#groupname').val();
  var des = $('#des').val();
  var status = $('#status').val();
  var id = $('.editId').val();
 
  if(groupname == '' || power == '' ){
      layer.msg('信息不完整',{
        time:900  ,           //时间
      });
      return false;
  }

  $.ajax({
      type:"get",
      url:"__APP__/admin/Role/add_edit?power="+power+'&groupname='+groupname+'&des='+des+'&status='+status+'&id='+id,
      success:function(data){
        // alert(data);
        returnInfo(data);

      }        
  })//ajax结束
}



//删除
function del(id){
  layui.use('layer', function(){
    var layer = layui.layer;
    layer.open({
      title: '询问框'
      ,content: '确定删除这个管理员吗？'
      ,offset: '100px'   
      ,yes: function(index, layer){
          $.ajax({
            type:"post",
            url:"__APP__/admin/Role/del",
            data:'id='+id,
            dataType:"json",//服务器返回类型
            success:function(data){
                // alert(data);
                 returnInfo(data);
            }
          })
      }
    })
  }); 
}

</script>


{include file="public/footer" /}


<!-- --------------------弹窗----------------------->


<script id="box2">
  <div class="x-body">
    <form action="" method="post" class="layui-form layui-form-pane lay_box">
      <input type="hidden" name="id" class='editId'>
      <!-- -->
      <div class="layui-form-item">
          <label for="name" class="layui-form-label">
              <span class="x-red">*</span> 角色名
          </label>
          <div class="layui-input-inline">
              <input type="text" id="groupname" name="groupname"  class="layui-input">
          </div>
      </div>
      <!-- -->
          <div class="layui-form-item" >
              <label  class="layui-form-label">
                  描述
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="des" name="des"  class="layui-input" style="width:500px">
              </div>
          </div>
      <!-- -->
      <!-- -->
      <div class="layui-form-item">
          <label for="L_repass" class="layui-form-label">
            <span class="x-red">*</span> 状态
          </label>
          
          <div class="layui-input-block">
            <input type="radio" name="status" id='status' value="1" title="启用" checked="">
            <input type="radio" name="status" id='status' value="2" title="冻结">
            
          </div>
      </div>
      
      <div class="layui-form-item layui-form-text">
          <label class="layui-form-label">
              拥有权限
          </label>
          <table  class="layui-table layui-input-block">
              <tbody>
                {foreach name="list" item="v" key="k" }
                  <tr>
                    <td width="120">
                        <input type="checkbox" name="power" id="qx{$v.id}" value="{$v.id}" lay-skin="primary" title="{$v.name}">
                    </td>
                    <td>
                      <div class="layui-input-block">
                        {foreach name="v['data']" item="vv" key="kk" }
                        
                          <input type="checkbox" name="power" id="qx{$vv.id}" value="{$vv.id}" lay-skin="primary" title="{$vv.name}">

                          {foreach name="vv['data2']" item="vvv" key="kkk" }
                            <input type="checkbox" name="power" id="qx{$vvv.id}" value="{$vvv.id}" lay-skin="primary" title="{$vvv.name}">
                          {/foreach} 

                        {/foreach} 
                        
                      </div>
                    </td>
                  </tr>
                {/foreach}


              </tbody>
          </table>
      </div>
      </form>
      <div class="layui-form-item">
        <a class="layui-btn" onclick="sub()">确定</a>
      </div>
   
  </div>
</script>